//
//  TBRRentDetailController.m
//  TBText
//
//  Created by yy on 2018/4/30.
//  Copyright © 2018年 yy. All rights reserved.
//

#import "TBRRentDetailController.h"

#import "TBROrderMessageEnumCell.h"
#import "TBROrderStatusCell.h"
#import "TBROrderCarMessageCell.h"
#import "TBROrderHeadView.h"

#import "TBRHomeModel.h"
#import <YYModel.h>
#import "BaseOperation.h"
#import "AppSetting.h"
@interface TBRRentDetailController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic,strong)NSArray *titleGoOutDesArray;
@property (nonatomic,strong)NSArray *titleGoOutDetailArray;

@property (nonatomic,strong)NSArray *titleCostDesArray;
@property (nonatomic,strong)NSArray *titleCostDetailArray;

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation TBRRentDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
    //加载数据
    [self loadData];
}

- (void)setupUI {
    //设置导航条
    [self setupNavItem];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBROrderMessageEnumCell" bundle:nil] forCellReuseIdentifier:@"TBROrderMessageEnumCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBROrderStatusCell" bundle:nil] forCellReuseIdentifier:@"TBROrderStatusCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBROrderCarMessageCell" bundle:nil] forCellReuseIdentifier:@"TBROrderCarMessageCellId"];
}

- (void)setupNavItem {
    self.titleText = @"订单详情";
}


#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return self.titleGoOutDetailArray.count;
    }
    if (section == 1 || section == 2) {
        return 1;
    }
    if (section == 3) {
        return self.titleCostDetailArray.count;
    }
    return 1;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //自定义cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self getIdentifier:indexPath] forIndexPath:indexPath];
    [self setupCell:cell indexPath:indexPath];
    return cell;
}

- (NSString *)getIdentifier:(NSIndexPath *)indexPath {
    NSString *iden = @"TBROrderMessageEnumCellId";
    if (indexPath.section == 0 || indexPath.section == 3) {
        iden = @"TBROrderMessageEnumCellId";
    }else if (indexPath.section == 1){
        iden = @"TBROrderStatusCellId";
    }else {
        iden = @"TBROrderCarMessageCellId";
    }
    return iden;
}

- (void)setupCell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
//#import "TBROrderMessageEnumCell.h"
//#import "TBROrderStatusCell.h"
//#import "TBROrderCarMessageCell.h"
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        TBROrderMessageEnumCell *cellEnumM= (TBROrderMessageEnumCell *)cell;
        cellEnumM.lbe_titleDes.text = self.titleGoOutDesArray[indexPath.row];
        cellEnumM.lbe_titleDetail.text = self.titleGoOutDetailArray[indexPath.row];
    }else if(indexPath.section == 1){
        TBROrderStatusCell *cellOrderStatus = (TBROrderStatusCell *)cell;
    }else if(indexPath.section == 2){
        TBROrderCarMessageCell *cellOrderCarMessage = (TBROrderCarMessageCell *)cell;
    }
    else if(indexPath.section == 3){
        TBROrderMessageEnumCell *cellEnumM= (TBROrderMessageEnumCell *)cell;
        cellEnumM.lbe_titleDes.text = self.titleCostDesArray[indexPath.row];
        cellEnumM.lbe_titleDetail.text = self.titleCostDetailArray[indexPath.row];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {return 137;}
    return indexPath.section == 2 ? 109 : 44;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        TBROrderHeadView *outOrderMessageView = [TBROrderHeadView orderHeadView];
        outOrderMessageView.frame = CGRectMake(0, 0, Width, 47);
        return outOrderMessageView;
    }
    if (section == 1) {
        TBROrderHeadView *outOrderStatusView = [TBROrderHeadView orderHeadView];
        outOrderStatusView.frame = CGRectMake(0, 0, Width, 47);
        return outOrderStatusView;
    }
    if (section == 2) {
        TBROrderHeadView *outOrderCarView = [TBROrderHeadView orderHeadView];
        outOrderCarView.frame = CGRectMake(0, 0, Width, 47);
        return outOrderCarView;
    }
    if (section == 3) {
        TBROrderHeadView *outOrderCostView = [TBROrderHeadView orderHeadView];
        outOrderCostView.frame = CGRectMake(0, 0, Width, 47);
        return outOrderCostView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 47;
}


// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
    [self loadNetData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    self.titleGoOutDesArray = @[@"上车时间",@"出发地",@"目的地",@"预计到达",@"乘车人",@"乘车人",@"备注"];
    self.titleCostDesArray = @[@"预估距离",@"预估耗时",@"预估价格",@"支付方式"];
    for (TBRRentGetMessageModel *getMessageModel in self.dataArray) {
        if ([getMessageModel.messageId isEqualToString:@"time"]) {
            self.onCarTime = [HelpObject changeNull:getMessageModel.detailName];
        }else if ([getMessageModel.messageId isEqualToString:@"onPlace"]) {
            self.onPlace = [HelpObject changeNull:getMessageModel.detailName];
        }else if ([getMessageModel.messageId isEqualToString:@"offPlace"]) {
            self.offPlace = [HelpObject changeNull:getMessageModel.detailName];
        }else if ([getMessageModel.messageId isEqualToString:@"carMessage"]) {
            self.carMessage = [HelpObject changeNull:getMessageModel.detailName];
        }else if ([getMessageModel.messageId isEqualToString:@"personMessage"]) {
            self.personMessage = [HelpObject changeNull:getMessageModel.detailName];
        }else if ([getMessageModel.messageId isEqualToString:@"carMessage"]) {
            self.carMessage = [HelpObject changeNull:getMessageModel.detailName];
        }
    }
    
    
    //
}

// MARK: - 获取网络数据-----
- (void)loadNetData {
    self.estimateOffTime = [HelpObject changeNull:@"2018-10-1 13:15"];
    //获取到网络数据后复制-----------
    self.estimateDistance = [HelpObject changeNull:@"48.8公里"];
    self.estimateDuratino = [HelpObject changeNull:@"1小时18分钟"];
    self.estimatePrice = [HelpObject changeNull:@"720.0元"];
    self.payMode = @"储值卡扣取";
    
    self.titleGoOutDetailArray = @[_onCarTime,_onPlace,_offPlace,_estimateOffTime,_personMessage,_remark];
    self.titleCostDetailArray = @[_estimateDistance,_estimateDuratino,_estimatePrice,_payMode];
    [self.tableView reloadData];
}
@end
